package com.peng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.peng.pojo.Clazz;
import com.peng.service.ClazzService;
import com.peng.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(@PathVariable("pageNo")Integer pageNo, @PathVariable("pageSize")Integer pageSize, String gradeName, String name){
        IPage<Clazz> iPage= clazzService.getClazzsByOpr(pageNo,pageSize,gradeName,name);
        return Result.ok(iPage);
    }

    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@RequestBody List<Integer> list  ){
        clazzService.removeByIds(list);
        return Result.ok();
    }

    @GetMapping("/getClazzs")
    public Result getClazzs(){
        return Result.ok(clazzService.list());
    }
}
